#include <stdio.h>
#include <e_file.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char **argv)
{
	struct flock lock;
	int fd;
	fd = open (argv[1],O_RDONLY);//打开文件的权限和需要加锁的类型需要保持一致	
	if(-1 == fd){
		perror("open ()");
		return -1;
	}
	lock.l_type = F_RDLCK;
	lock.l_whence = SEEK_SET;
	lock.l_start = 0;
	lock.l_len = 7;

	int f = fcntl (fd, F_SETLK,&lock);
	if(-1 == f){
		perror("fctnl()");
	}
	printf("add read lock success ...\n");
	getchar();
	close(fd);
	return 0;
}

